package com.rules.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rules.admin.entity.SpringCloudModel;
import com.rules.admin.service.SpringCloudService;
import com.rules.admin.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping({"/springCloud"})
@Controller
public class SpringCloudController {
   @Autowired
   private SpringCloudService springCloudService;

   @RequestMapping(
      value = {"springCloud_page"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public IPage<SpringCloudModel> queryPage(SpringCloudModel springCloudModel, IPage<SpringCloudModel> page) {
      return this.springCloudService.queryPage(springCloudModel, page);
   }

   @RequestMapping(
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public Map<String, Object> addRemote(@RequestBody SpringCloudModel springCloudModel) {
      this.springCloudService.save(springCloudModel);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getspringCloud(@PathVariable("id") String id) {
      SpringCloudModel springCloudModel = (SpringCloudModel)this.springCloudService.getById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData(springCloudModel);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.DELETE}
   )
   @ResponseBody
   public Map<String, Object> deletespringCloud(@PathVariable("id") String id) {
      this.springCloudService.removeById(Long.parseLong(id));
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      method = {RequestMethod.PUT}
   )
   @ResponseBody
   public Map<String, Object> updatespringCloud(@RequestBody SpringCloudModel springCloudModel) {
      this.springCloudService.save(springCloudModel);
      return ResultUtils.getSuccessResultData();
   }
}
